home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 034a / twview82.zip / CONVERT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-04  |  7KB  |  263 lines

  1. { Part one will parse a log file, and store explored sectors; then
  2. create a text file that you can feed to the computer that will give you
  3. a map of the universe.  Part two will take a log file generated from
  4. feeding the first to the computer, and create a data file that can
  5. be fed into something else.
  6. }
  7. program converter;
  8.  
  9. {$I headers.inc}
  10.  
  11. const
  12.   Version  = ' dos 0.82b';
  13.  
  14. var
  15.   filename : string;
  16.   errorCode,
  17.   n : integer;
  18.   f, g : text;
  19.   space : TheVoid;
  20.  
  21. function ReadNumber : integer;
  22. { Read the next number from text file f.  If there is no next number,
  23. return 0.}
  24. var
  25.   number : integer;
  26.   ch : char;
  27.   i  : integer;
  28. begin
  29.   number := 0;
  30.   if not eof( f ) then
  31.     begin
  32.       read( f, ch );
  33.       while (ch in [' ',#9, #10, #13]) and (not eof(f)) do read( f, ch );
  34.       repeat
  35.         if ch in ['0'..'9'] then
  36.           number := number * 10 + ord( ch ) - ord( '0' );
  37.         if not eof( f ) then
  38.           read( f, ch )
  39.         else
  40.           ch := #26;
  41.       until (not (ch in ['0'..'9']));
  42.       if ch = '[' then     {hit [PAUSE]^h^h^h^h^h^h^h}
  43.         for i := 1 to 32 do
  44.           read(f, ch);
  45.     end;
  46.   ReadNumber := number;
  47. end;
  48.  
  49. procedure skip( var f : text; n : integer);
  50. var
  51.   ch : char;
  52. begin
  53.   for n := 1 to n do
  54.     read( f, ch );
  55. end; {skip}
  56.  
  57. {$I gsdata.inc }
  58.  
  59. procedure PartI;
  60. var
  61.   newcount,
  62.   count, n : integer;
  63.   line     : string;
  64.   ch       : char;
  65. begin
  66.   newcount := 0;
  67.   repeat
  68.     readln( f, line );
  69.   until (pos( 'sectors:', line ) > 0) or eof( f );
  70.   n := readNumber;
  71.   count := 0;
  72.   while (not eof( f )) and (n>0) do
  73.     begin
  74.       count := count + 1;
  75.       if space.sectors[n].number = 0 then
  76.         begin
  77.           newcount := newcount + 1;
  78.           writeln('New sector info for ', n );
  79.           writeln( g, 'I', n );
  80.           writeln( g, 'R', n );
  81.         end; {if}
  82.       n := readNumber;
  83.     end; {while}
  84.   writeln('You have explored ', count, ' sectors.');
  85.   writeln('Explored ', newcount, ' new sectors.');
  86.   write('Do you want a refresh on your ports? ');
  87.   readln( ch );
  88.   if ch in ['Y','y'] then
  89.     for n := 1 to maxSector do
  90.       if space.sectors[n].PortType <> NotAPort then
  91.         writeln( g, 'R', n );
  92.   close( g );
  93. end; {PartI}
  94.  
  95. procedure LoadData( var TheSector : SectorInfo );
  96. var
  97.   ch : char;
  98. begin
  99.   with TheSector do
  100.     begin
  101.       number := 0;
  102.       repeat
  103.         read( f, ch );
  104.       until ch = ':';
  105.       ch := '-';
  106.       while ch = '-' do
  107.         begin
  108.           number := number + 1;
  109.           data[ number ] := ReadNumber;
  110.           read( f, ch );
  111.         end; {while}
  112.       readln( f );
  113.     end; {with}
  114. end; {LoadData}
  115.  
  116. procedure CheckData( var TheSector : SectorInfo );
  117. var
  118.   t  : warpIndex;
  119.   ch : char;
  120. begin
  121.   repeat
  122.     read( f, ch );
  123.   until ch = ':';
  124.   for t := 1 to TheSector.number do
  125.     begin
  126.       if TheSector.data[ t ] <> ReadNumber then
  127.         begin
  128.           write('Log data doesn''t match input data!  Exiting without save!');
  129.           halt;
  130.         end; {if}
  131.       read( f, ch );
  132.     end; {for}
  133.   readln( f );
  134. end; {Data}
  135.  
  136. procedure ProcessWarps( var space : TheVoid );
  137. var
  138.   s    : integer;
  139.   line : string;
  140. begin
  141.   skip( f, 6);
  142.   s := ReadNumber;
  143.   writeln('Processing sector ', s );
  144.   if s = 0 then
  145.     begin
  146.       writeln('Something is screwy.  Exiting.');
  147.       readln;
  148.       writeln('Screwup after line:');
  149.       writeln( line );
  150.       readln;
  151.       SaveData( g, space );
  152.       readln;
  153.       halt;
  154.     end;
  155.   if space.sectors[s].number > 0 then
  156.     CheckData( space.sectors[ s ] )
  157.   else
  158.     LoadData( space.sectors[ s ] );
  159. end; {ProcessWarps}
  160.  
  161. {$I PortStat.inc }
  162. {$I status.inc }
  163.  
  164. procedure ProcessPorts( var space    : TheVoid;
  165.                             line     : string );
  166. var
  167.   LeftBrack, s : integer;
  168.   ch : char;
  169.   err : string;
  170. begin
  171.   LeftBrack := pos( ']', line );
  172.   delete( line, 1, LeftBrack );
  173.   if bval( line, s ) then
  174.     writeln('error parsing sector ', line )
  175.   else if (s<1) or (s>maxSector) then
  176.     writeln('sector value', s, ' out of bounds ')
  177.   else if not eof( f ) then
  178.     begin
  179.       readln( f );           { next line is blank }
  180.       if not eof( f ) then
  181.         begin
  182.           readln( f, line );
  183.           if (copy( line, 1, 8) = 'Commerce') and (not eof( f )) then
  184.             begin
  185.               if pos( 'Stargate Alpha', line ) > 0 then
  186.                 begin
  187.                   writeln('StarDock found in sector ', s);
  188.                   space.dock := s;
  189.                   space.sectors[ s ].etc := space.sectors[ s ].etc or StarDock;
  190.                 end;
  191.               space.sectors[ s ].etc := space.sectors[ s ].etc or IsPort;
  192.               GetPortStatus( s, space.sectors[ s ].portType, line, space.Ports );
  193.               writeln('Status on port ', s, ' : ', status(space.sectors[s].portType) );
  194.             end {if}
  195.           else
  196.             space.sectors[s].portType := NotAPort;
  197.         end; {if}
  198.     end; {eof}
  199. end; {ProcessPorts}
  200.  
  201. procedure PartII( var space : TheVoid );
  202. var
  203.   line : string;
  204.   ch : char;
  205.   s, i : integer;
  206.   finished : boolean;
  207. begin
  208.   while not eof( f ) do
  209.     begin
  210.       readln( f, line );
  211.       if pos( 'examine?', line ) > 0 then
  212.         processWarps( space )
  213.       else if pos( 'What sector is the port in?', line) > 0 then
  214.         processPorts( space, line );
  215.     end; {while}
  216.   writeln('Log processed... updating now.');
  217.   SaveData( g, space );
  218. end; {PartII}
  219.  
  220. {$I part3.inc}
  221. {$I part4.inc}
  222.  
  223. begin {main}
  224.   writeln('Tradewars Data Base generator: version', Version);
  225.   writeln;
  226.   GetData( space );
  227.   writeln('Choices:');
  228.   writeln('  (1)  Read "Explored Sectors" list for newly scanned sectors');
  229.   writeln('  (2)  Read log files for inter-warp and port information');
  230.   writeln('  (3)  Read "Unexplored Sectors" list for newly scanned sectors');
  231.   writeln('  (4)  Read "Fighter Display" list for fighter clouds');
  232.   writeln;
  233.   write('Your choice?  (1, 2, 3, or 4) ');
  234.   readln( n );
  235.   repeat
  236.     case n of
  237.       1 : write('Name of "Explored Sectors" file? ');
  238.       2 : write('Name of log file? ');
  239.       3 : write('Name of "Unexplored Sectors" file? ');
  240.       4 : write('Name of "Deployed Fighter Scan" file? ');
  241.     end; {case}
  242.     readln( filename );
  243.     if filename = '' then
  244.       halt;
  245.     {$I-}
  246.     assign( f, filename);
  247.     reset( f );
  248.     {$I+}
  249.     errorCode := ioResult;
  250.     if errorCode <> 0 then writeln('Error ', errorCode, ' opening file!');
  251.   until errorCode = 0;
  252.   write('Name of file to generate? ');
  253.   readln( filename );
  254.   assign( g, filename );
  255.   rewrite( g );
  256.   case n of
  257.     1 : partI;
  258.     2 : partII( space);
  259.     3 : partIII;
  260.     4 : partIV( space );
  261.   end; {case}
  262.   close( f );
  263. end.